package IO;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import ItemUser.MoiveRate;
import ItemUser.UserRate;
import tool.Similarity;

public class Main {

	public static void main(String[] args) {
		DataResources resources = new DataResources("recommender_system_data\\simtable");
		FileWriter fw = null;
		try {
			resources.createFile();
			fw = new FileWriter(resources.getFile());
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		DataHandler dataHandler = new DataHandler("recommender_system_data\\ratings_train.dat");
		System.out.println("启动");
		try {
			dataHandler.mapByUserID();
			dataHandler.mapByMovieID();
			ArrayList<MoiveRate> user = dataHandler.getUserToItem().get(Long.valueOf(2).longValue());
			
			for(int i = 1;i <= dataHandler.getItemToUser().size();i++){
				long moiveid = i;
				ArrayList<UserRate> moive1 = dataHandler.getItemToUser().get(moiveid);
				for(int j = 1;j <= i;j++){
					ArrayList<UserRate> moive2 = dataHandler.getItemToUser().get((long)j);
					if(moive1 != null && moive2 != null){
						fw.write(moiveid+","+j+":"+Similarity.sim(moive1, moive2)+"\t");
						System.out.println(moiveid+","+j+":"+Similarity.sim(moive1, moive2));
					}
				}
			}
			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("结束");
	}

}
